import Vue from 'vue'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import './assets/css/reset.css'
import './assets/css/index.less'
//这里需要引入mock.js 才能进行调用 vue里面全局调用
import '@/api/mock.js'


Vue.prototype.$bus = new Vue()


import {
  Breadcrumb,
  BreadcrumbItem,
  Button,
  Col,
  Checkbox,
  Container,
  Main,
  Header,
  Aside,
  Menu,
  Submenu,
  MenuItem,
  MenuItemGroup,
  Dropdown,
  DropdownMenu,
  DropdownItem,
  Row,
  Card,
  Table,
  TableColumn,
  Tag,
  Form,
  FormItem,
  Input,
  Select,
  DatePicker,
  Option,
  Switch,
  Dialog,
  Pagination,
  MessageBox,
  Message
} from 'element-ui'

Vue.config.productionTip = false
Vue.use(Button)
Vue.use(Breadcrumb)
Vue.use(BreadcrumbItem)
Vue.use(Checkbox)
Vue.use(Container)
Vue.use(Main)
Vue.use(Header)
Vue.use(Aside)
Vue.use(Menu)
Vue.use(Submenu)
Vue.use(MenuItem)
Vue.use(MenuItemGroup)
Vue.use(Dropdown)
Vue.use(DropdownMenu)
Vue.use(DropdownItem)
Vue.use(Row)
Vue.use(Card)
Vue.use(Col)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Tag)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Select)
Vue.use(DatePicker)
Vue.use(Switch)
Vue.use(Option)
Vue.use(Dialog)
Vue.use(Pagination)


Vue.prototype.$axios = axios
Vue.prototype.$confirm = MessageBox.confirm
Vue.prototype.$message = Message

router.beforeEach((to,from,next) => {
  //首先获取token信息 目的是为了防止页面刷新之后vuex丢失我们的token信息
  store.commit('getToken')
  // 这里拿到store中的token
  const token = store.state.user.token
  // 然后进行判断,如果我们的token不存在,并且to的不是登录页
  if(!token && to.name !== 'Login') {
    next({ name:'Login' })
  } else  {
    next()
  }
})

new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount('#app')
